home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 December / PSL Monthly Shareware CD-ROM (Public Software Library)(December 1994).bin / prgmming / dos / c1 / readtest.c < prev    next >
Text File  |  1991-04-30  |  4KB  |  184 lines

  1.  
  2.      ╔══════════════════════════════════════════╗
  3.      ║                        ║
  4.      ║        A SIMPLE TEXT FILE LISTER        ║
  5.      ║                        ║
  6.      ║                        ║
  7.      ║ created by David Smith, because all the    ║
  8.      ║ file listers I found are written in    ║
  9.      ║ assembly language, and not in        ║
  10.      ║ "C".                    ║
  11.      ║                        ║
  12.      ║ After all, us "C"ers need to stand up    ║
  13.      ║ for our heritage, huh ???        ║
  14.      ║                        ║
  15.      ║                        ║
  16.      ║       QUESTIONS OR COMMENTS ??        ║
  17.      ║                        ║
  18.      ║         DAVID SMITH            ║
  19.      ║    Compuserve 71441,2723            ║
  20.      ║                        ║
  21.      ║                        ║
  22.      ╚══════════════════════════════════════════╝
  23.  
  24.  Bumped up in Turbo C++ April 7, 1991.
  25.  
  26.  
  27. 
  28.  
  29.  
  30. #include <conio.h>
  31. #include <stdio.h>
  32. #include <dos.h>
  33.  
  34. void other(void);      /* functions */
  35. void minim(void);
  36. void maxim(void);
  37. void display(int start, int end);
  38.  
  39. FILE *stream;              /* variables we use */
  40. int i=1,j,max=0,c=3,t,b,x,y,a;
  41. long pos[200];
  42. char line[93],*file;
  43.  
  44. void main(int argc, char *argv[])
  45. {
  46.  
  47. _setcursortype(_NOCURSOR);
  48. strcpy(file,argv[1]);
  49.  
  50. if((stream=fopen(argv[1],"rt"))==NULL)     /* open file */
  51.  {
  52.  printf("Problems opening file");
  53.  exit();
  54.  }
  55. fseek(stream,0L,SEEK_SET);
  56.  
  57. clrscr();
  58.  
  59.  do{             /* mark all lines of text with numbers */
  60.  if(feof(stream)) break;
  61.  pos[i]=ftell(stream);
  62.  fgets(line,90,stream);
  63.  i++;
  64.  max++;
  65.  }  while(!feof(stream));
  66.  
  67.  b=j;
  68.  display(1,25);   /*  set cursor position to top of text, then
  69.  x=1;           *  call DISPLAY to print out 24 lines
  70.  j=25;           */
  71.  
  72. other();
  73. }
  74.  
  75.  
  76. void other(void)
  77. {
  78.  
  79. union REGS r;  /* set up to call the screen scrolling function */
  80. r.h.ch=0;
  81. r.h.cl=0;
  82. r.h.dh=23;
  83. r.h.dl=79;
  84. r.h.bh=5;
  85. r.h.al=1;
  86.  
  87. t=getch();    /* get user input */
  88.  
  89. if(t==72){
  90.     r.h.ah=7;        /* call ROM BIOS to scroll up */
  91.     int86(0x10,&r,&r);
  92.     j--;            /* decrease file pointer */
  93.     x=j-24;
  94.     if(x<1) minim();
  95.     fseek(stream,pos[x],SEEK_SET); /* fill in blank space created by
  96.     fgets(line,90,stream);        * scrolling up
  97.     gotoxy(1,1);            */
  98.     cprintf("%s",line);
  99.       }
  100. if(t==80){
  101.     gotoxy(1,25);
  102.     r.h.ah=6;       /* call ROM BIOS to scroll down */
  103.     int86(0x10,&r,&r);
  104.     j++;
  105.     gotoxy(1,24);
  106.     x=j-24;
  107.     if(j>=max) maxim();
  108.     fseek(stream,pos[j],SEEK_SET);    /* fill in again */
  109.     fgets(line,93,stream);
  110.     cprintf("%s",line);
  111.        }
  112. if(t==13) c++;    /* increase color for text */
  113.  
  114. if(t==81){
  115.    clrscr();      /* if user wants a page to scroll, we move pointer
  116.    j+=23;       *   down 23 lines, then call display to fill in
  117.    gotoxy(1,24);   */    the blanked screen
  118.    x=j-24;
  119.    if(j>=max) maxim();
  120.    b=1;
  121.    display(x,j);
  122.    }
  123.  
  124. if(t==73){        /* same with page up !! */
  125.    clrscr();
  126.    j-=23;
  127.    x=j-24;
  128.    if(x<1) minim();
  129.    b=1;
  130.    display(x,j);
  131.    }
  132.  
  133. if(c>15) c=1;      /* if text color gets too high, bring it to ONE */
  134.  
  135. if(t==27)
  136.  {
  137.  fcloseall();
  138.  _setcursortype(_NORMALCURSOR); /*   if ESC is entered, close up and
  139.  exit();             *   sign off for the day
  140.  }                 */
  141. textcolor(c);    /*recover the text color in case it was changed to red
  142. other();       because of an error (endoffile, beginningoffile)    */
  143. }
  144.  
  145. void display(int start, int end)
  146. {
  147. for(a=start;a<=end;a++)      /* display 24 lines of text */
  148.  {
  149.  fseek(stream,pos[a],SEEK_SET);
  150.  fgets(line,92,stream);
  151.  gotoxy(1,b);
  152.  cprintf("%s",line);
  153.  b++;
  154.  }
  155. }
  156.  
  157. void minim(void)     /* if beginning of file has been passed, clear screen
  158. {            then goto position 1.  Then, present beginfile message */
  159.    x=1;
  160.    j=25;
  161.    clrscr();
  162.    b=2;
  163.    display(1,23);
  164.    gotoxy(1,1);
  165.    j-=3;
  166.    textcolor(RED);
  167.    cprintf("                       *--* BEGINNING OF FILE *--*                  ");
  168.    other();
  169. }
  170.  
  171. void maxim(void)
  172. {
  173.    j=max-1;          /* do the same with end of file */
  174.    x=j-24;
  175.    clrscr();
  176.    b=1;
  177.    display(x,max);
  178.    gotoxy(1,24);
  179.    j +=2;
  180.    textcolor(RED);
  181.    cprintf("                       *-* END OF FILE *-*                          ");
  182.    other();
  183. }
  184.